﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* 简单的js类继承
*/

define(function (require, exports, module) {
    var FXREADER = require('./FXReader');
    FXREADER.Interface = (function () {
        return function (name, methods) {
            if (arguments.length != 2) {
                throw new Error("Interface constructor called with " + arguments.length
              + "arguments, but expected exactly 2.");
            }

            this.name = name;
            this.methods = [];
            for (var i = 0, len = methods.length; i < len; i++) {
                if (typeof methods[i] !== 'string') {
                    throw new Error("Interface constructor expects method names to be "
                  + "passed in as a string.");
                }
                this.methods.push(methods[i]);
            }
        };
    })();

    // Static class method.
    FXREADER.Interface.ensureImplements = function (object) {
    	return ;//
        if (arguments.length < 2) {
            throw new Error("Function Interface.ensureImplements called with " +
              arguments.length + "arguments, but expected at least 2.");
        }

        for (var i = 1, len = arguments.length; i < len; i++) {
            var interface = arguments[i];
            if (interface.constructor !== FXREADER.Interface) {
                throw new Error("Function Interface.ensureImplements expects arguments "
                  + "two and above to be instances of Interface.");
            }

            for (var j = 0, methodsLen = interface.methods.length; j < methodsLen; j++) {
                var method = interface.methods[j];
                if (!object[method] || typeof object[method] !== 'function') {
                    throw new Error("Function Interface.ensureImplements: object "
                      + "does not implement the " + interface.name
                      + " interface. Method " + method + " was not found.");
                }
            }
        }
    };

    /* Extend function. */

    FXREADER.Interface.extend = function (subClass, superClass) {
        var F = function () { };
        F.prototype = superClass.prototype;
        subClass.prototype = new F();
        subClass.prototype.constructor = subClass;

        subClass.superclass = superClass.prototype;
        if (superClass.prototype.constructor == Object.prototype.constructor) {
            superClass.prototype.constructor = superClass;
        }
    }

    return FXREADER.Interface;
});